package model;

import java.sql.*;
import java.util.Date;
import java.util.List;
import dal.*;
import util.*;

public class ProjectModel implements IModel {

	public static class FieldNames {
		public static String Id = "Id";
		public static String Name = "Name";
		public static String Code = "Code";
		public static String Description = "Description";
		public static String IdType = "IdType";
		public static String Pm = "Pm";
		public static String IdCompany = "IdCompany";
		public static String IsTemplate = "IsTemplate";
		public static String Status = "Status";
		public static String EventDate = "EventDate";
		public static String PlanStartDate = "PlanStartDate";
		public static String PlanEndDate = "PlanEndDate";
		public static String RealStartDate = "RealStartDate";
		public static String RealEndDate = "RealEndDate";
		public static String Attendees = "Attendees";
		public static String IdVenue = "IdVenue";
		public static String Created = "Created";
		public static String Creator = "Creator";
		public static String Updated = "Updated";
		public static String Updator = "Updator";
		public static String Deleted = "Deleted";
		public static String DeletionTime = "DeletionTime";
		public static String Avatar = "Avatar";
		public static String Budget = "Budget";
	
	}

	public class ErrorMessages {
		public String Id = "";
		public String Name = "";
		public String Code = "";
		public String Description = "";
		public String IdType = "";
		public String Pm = "";
		public String IdCompany = "";
		public String IsTemplate = "";
		public String Status = "";
		public String EventDate = "";
		public String PlanStartDate = "";
		public String PlanEndDate = "";
		public String RealStartDate = "";
		public String RealEndDate = "";
		public String Attendees = "";
		public String IdVenue = "";
		public String Created = "";
		public String Creator = "";
		public String Updated = "";
		public String Updator = "";
		public String Deleted = "";
		public String DeletionTime = "";
		public String Avatar = "";
		public String Budget = "";
	
	}

    public ErrorMessages errMsgs = new ErrorMessages();

	public String[] errMsgList = null;

// private variables
private int _id = Integer.MIN_VALUE;
private String _name = null;
private String _code = null;
private String _description = null;
private int _id_type = Integer.MIN_VALUE;
private int _pm = Integer.MIN_VALUE;
private int _id_company = Integer.MIN_VALUE;
private boolean _is_template = false;
private boolean _isis_templateSet = false;
private int _status = Integer.MIN_VALUE;
private Date _event_date = null;
private Date _plan_start_date = null;
private Date _plan_end_date = null;
private Date _real_start_date = null;
private Date _real_end_date = null;
private int _attendees = Integer.MIN_VALUE;
private int _id_venue = Integer.MIN_VALUE;
private Date _created = null;
private int _creator = Integer.MIN_VALUE;
private Date _updated = null;
private int _updator = Integer.MIN_VALUE;
private boolean _deleted = false;
private boolean _isdeletedSet = false;
private Date _deletion_time = null;
private String _avatar = null;
private double _budget = Double.MAX_VALUE;


	public ProjectModel() {
	}

// get/set
public int getId() {
		return _id;
	}
public void setId(int value) {
		_id = value;
	}
public String getIdToString() {
		if (_id == Integer.MIN_VALUE
				|| _id == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id);
		}
	}
public String getName() {
		return _name;
	}
public void setName(String value) {
		_name = value;
	}
public String getNameToString() {
		if (_name != null) {
			return HtmlUtil.genHtml(_name);
		} else {
			return "";
		}
	}
public String getCode() {
		return _code;
	}
public void setCode(String value) {
		_code = value;
	}
public String getCodeToString() {
		if (_code != null) {
			return HtmlUtil.genHtml(_code);
		} else {
			return "";
		}
	}
public String getDescription() {
		return _description;
	}
public void setDescription(String value) {
		_description = value;
	}
public String getDescriptionToString() {
		if (_description != null) {
			return HtmlUtil.genHtml(_description);
		} else {
			return "";
		}
	}
public int getIdType() {
		return _id_type;
	}
public void setIdType(int value) {
		_id_type = value;
	}
public String getIdTypeToString() {
		if (_id_type == Integer.MIN_VALUE
				|| _id_type == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_type);
		}
	}
public int getPm() {
		return _pm;
	}
public void setPm(int value) {
		_pm = value;
	}
public String getPmToString() {
		if (_pm == Integer.MIN_VALUE
				|| _pm == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_pm);
		}
	}
public int getIdCompany() {
		return _id_company;
	}
public void setIdCompany(int value) {
		_id_company = value;
	}
public String getIdCompanyToString() {
		if (_id_company == Integer.MIN_VALUE
				|| _id_company == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_company);
		}
	}
public boolean getIsTemplate() {
		return _is_template;
	}
public void setIsTemplate(boolean value) {
		_is_template = value;
		_isis_templateSet = true;
	}
public boolean getIsTemplateSet() {
		return _isis_templateSet;
	}
	public String getIsTemplateToString() {
		if (_isis_templateSet) {
			return HtmlUtil.genHtml(_is_template);
		} else {
			return "";
		}
	}
public int getStatus() {
		return _status;
	}
public void setStatus(int value) {
		_status = value;
	}
public String getStatusToString() {
		if (_status == Integer.MIN_VALUE
				|| _status == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_status);
		}
	}
public Date getEventDate() {
		return _event_date;
	}
public void setEventDate(Date value) {
		_event_date = value;
	}
public String getEventDateToString() {
		if (_event_date != null) {
			return StringUtil.toDateTimeString(_event_date);
		} else {
			return "";
		}
	}
public Date getPlanStartDate() {
		return _plan_start_date;
	}
public void setPlanStartDate(Date value) {
		_plan_start_date = value;
	}
public String getPlanStartDateToString() {
		if (_plan_start_date != null) {
			return StringUtil.toDateTimeString(_plan_start_date);
		} else {
			return "";
		}
	}
public Date getPlanEndDate() {
		return _plan_end_date;
	}
public void setPlanEndDate(Date value) {
		_plan_end_date = value;
	}
public String getPlanEndDateToString() {
		if (_plan_end_date != null) {
			return StringUtil.toDateTimeString(_plan_end_date);
		} else {
			return "";
		}
	}
public Date getRealStartDate() {
		return _real_start_date;
	}
public void setRealStartDate(Date value) {
		_real_start_date = value;
	}
public String getRealStartDateToString() {
		if (_real_start_date != null) {
			return StringUtil.toDateTimeString(_real_start_date);
		} else {
			return "";
		}
	}
public Date getRealEndDate() {
		return _real_end_date;
	}
public void setRealEndDate(Date value) {
		_real_end_date = value;
	}
public String getRealEndDateToString() {
		if (_real_end_date != null) {
			return StringUtil.toDateTimeString(_real_end_date);
		} else {
			return "";
		}
	}
public int getAttendees() {
		return _attendees;
	}
public void setAttendees(int value) {
		_attendees = value;
	}
public String getAttendeesToString() {
		if (_attendees == Integer.MIN_VALUE
				|| _attendees == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_attendees);
		}
	}
public int getIdVenue() {
		return _id_venue;
	}
public void setIdVenue(int value) {
		_id_venue = value;
	}
public String getIdVenueToString() {
		if (_id_venue == Integer.MIN_VALUE
				|| _id_venue == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_id_venue);
		}
	}
public Date getCreated() {
		return _created;
	}
public void setCreated(Date value) {
		_created = value;
	}
public String getCreatedToString() {
		if (_created != null) {
			return StringUtil.toDateTimeString(_created);
		} else {
			return "";
		}
	}
public int getCreator() {
		return _creator;
	}
public void setCreator(int value) {
		_creator = value;
	}
public String getCreatorToString() {
		if (_creator == Integer.MIN_VALUE
				|| _creator == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_creator);
		}
	}
public Date getUpdated() {
		return _updated;
	}
public void setUpdated(Date value) {
		_updated = value;
	}
public String getUpdatedToString() {
		if (_updated != null) {
			return StringUtil.toDateTimeString(_updated);
		} else {
			return "";
		}
	}
public int getUpdator() {
		return _updator;
	}
public void setUpdator(int value) {
		_updator = value;
	}
public String getUpdatorToString() {
		if (_updator == Integer.MIN_VALUE
				|| _updator == Integer.MAX_VALUE) {
			return "";
		} else {
			return Integer.toString(_updator);
		}
	}
public boolean getDeleted() {
		return _deleted;
	}
public void setDeleted(boolean value) {
		_deleted = value;
		_isdeletedSet = true;
	}
public boolean getDeletedSet() {
		return _isdeletedSet;
	}
	public String getDeletedToString() {
		if (_isdeletedSet) {
			return HtmlUtil.genHtml(_deleted);
		} else {
			return "";
		}
	}
public Date getDeletionTime() {
		return _deletion_time;
	}
public void setDeletionTime(Date value) {
		_deletion_time = value;
	}
public String getDeletionTimeToString() {
		if (_deletion_time != null) {
			return StringUtil.toDateTimeString(_deletion_time);
		} else {
			return "";
		}
	}
public String getAvatar() {
		return _avatar;
	}
public void setAvatar(String value) {
		_avatar = value;
	}
public String getAvatarToString() {
		if (_avatar != null) {
			return HtmlUtil.genHtml(_avatar);
		} else {
			return "";
		}
	}
public double getBudget() {
		return _budget;
	}
public void setBudget(double value) {
		_budget = value;
	}
	public String getBudgetToString() {
		if (_budget == Double.MIN_VALUE || _budget == Double.MAX_VALUE) {
			return "";
		} else {
			return StringUtil.toString(_budget);
		}
	}


	@Override
	public int[] getPrimaryKey() {
		int[] ids = new int[1];
		ids[0] = getId();
		return ids;
	}

	@Override
	public IModel readFromResultSet(ResultSet rs) throws SQLException {
		ProjectModel model = null;

			model = new ProjectModel();

// read fields
{
				int value = rs.getInt("id");
				if (!rs.wasNull()) {
					model.setId(value);
				}
			}
{
				String value = rs.getString("name");
				if (!rs.wasNull()) {
					model.setName(value);
				}
			}
{
				String value = rs.getString("code");
				if (!rs.wasNull()) {
					model.setCode(value);
				}
			}
{
				String value = rs.getString("description");
				if (!rs.wasNull()) {
					model.setDescription(value);
				}
			}
{
				int value = rs.getInt("id_type");
				if (!rs.wasNull()) {
					model.setIdType(value);
				}
			}
{
				int value = rs.getInt("pm");
				if (!rs.wasNull()) {
					model.setPm(value);
				}
			}
{
				int value = rs.getInt("id_company");
				if (!rs.wasNull()) {
					model.setIdCompany(value);
				}
			}
{
				boolean value = rs.getBoolean("is_template");
				if (!rs.wasNull()) {
					model.setIsTemplate(value);
				}
			}
{
				int value = rs.getInt("status");
				if (!rs.wasNull()) {
					model.setStatus(value);
				}
			}
{
				Date value = rs.getTimestamp("event_date");
				if (!rs.wasNull()) {
					model.setEventDate(value);
				}
			}
{
				Date value = rs.getTimestamp("plan_start_date");
				if (!rs.wasNull()) {
					model.setPlanStartDate(value);
				}
			}
{
				Date value = rs.getTimestamp("plan_end_date");
				if (!rs.wasNull()) {
					model.setPlanEndDate(value);
				}
			}
{
				Date value = rs.getTimestamp("real_start_date");
				if (!rs.wasNull()) {
					model.setRealStartDate(value);
				}
			}
{
				Date value = rs.getTimestamp("real_end_date");
				if (!rs.wasNull()) {
					model.setRealEndDate(value);
				}
			}
{
				int value = rs.getInt("attendees");
				if (!rs.wasNull()) {
					model.setAttendees(value);
				}
			}
{
				int value = rs.getInt("id_venue");
				if (!rs.wasNull()) {
					model.setIdVenue(value);
				}
			}
{
				Date value = rs.getTimestamp("created");
				if (!rs.wasNull()) {
					model.setCreated(value);
				}
			}
{
				int value = rs.getInt("creator");
				if (!rs.wasNull()) {
					model.setCreator(value);
				}
			}
{
				Date value = rs.getTimestamp("updated");
				if (!rs.wasNull()) {
					model.setUpdated(value);
				}
			}
{
				int value = rs.getInt("updator");
				if (!rs.wasNull()) {
					model.setUpdator(value);
				}
			}
{
				boolean value = rs.getBoolean("deleted");
				if (!rs.wasNull()) {
					model.setDeleted(value);
				}
			}
{
				Date value = rs.getTimestamp("deletion_time");
				if (!rs.wasNull()) {
					model.setDeletionTime(value);
				}
			}
{
				String value = rs.getString("avatar");
				if (!rs.wasNull()) {
					model.setAvatar(value);
				}
			}
{
				double value = rs.getDouble("budget");
				if (!rs.wasNull()) {
					model.setBudget(value);
				}
			}
		

		return model;
	}

	@Override
	public PreparedStatement genSelectStatement(Connection dbConn, IModel query)
			throws SQLException {
		String sql = "SELECT * FROM sp_project_select(:id);";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

        ProjectModel obj = (ProjectModel )query;
		
// set parameters
st.setObject("id", obj.getId());


		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genSelectListStatement(Connection dbConn,
			IModelExt query) throws SQLException {
		String sql = "SELECT * FROM sp_project_selectList(:limit, :offset, :id,:name,:code,:description,:id_type,:pm,:id_company,:is_template,:status,:event_dateFrom,:event_dateTo,:plan_start_dateFrom,:plan_start_dateTo,:plan_end_dateFrom,:plan_end_dateTo,:real_start_dateFrom,:real_start_dateTo,:real_end_dateFrom,:real_end_dateTo,:attendees,:id_venue,:createdFrom,:createdTo,:creator,:updatedFrom,:updatedTo,:updator,:deleted,:deletion_timeFrom,:deletion_timeTo,:avatar,:budget)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		ProjectModelExt obj = (ProjectModelExt) query;

		if (obj.getLimit() != Integer.MIN_VALUE) {
			st.setObject("limit", obj.getLimit());
		}  else {
			st.setObject("limit", Integer.MAX_VALUE);
		}
		if (obj.getOffset() != Integer.MIN_VALUE) {
			st.setObject("offset", obj.getOffset());
		}  else {
			st.setObject("offset", 0);
		}

// set parameters
if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
            st.setObject("id", null);
}
if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
            st.setObject("name", null);
}
if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
            st.setObject("code", null);
}
if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
            st.setObject("description", null);
}
if (obj.getIdType() != Integer.MIN_VALUE) {
			st.setObject("id_type", obj.getIdType());
		} else {
            st.setObject("id_type", null);
}
if (obj.getPm() != Integer.MIN_VALUE) {
			st.setObject("pm", obj.getPm());
		} else {
            st.setObject("pm", null);
}
if (obj.getIdCompany() != Integer.MIN_VALUE) {
			st.setObject("id_company", obj.getIdCompany());
		} else {
            st.setObject("id_company", null);
}
		if (obj.getIsTemplateSet()) {
			st.setObject("is_template", obj.getIsTemplate());
		} else {
            st.setObject("is_template", null);
}
if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
            st.setObject("status", null);
}
if (obj.getEventDateFrom() != null) {
			st.setObject("event_dateFrom", obj.getEventDateFrom());
		} else {
			st.setObject("event_dateFrom", null);
		}
		if (obj.getEventDateTo() != null) {
			st.setObject("event_dateTo", obj.getEventDateTo());
		} else {
            st.setObject("event_dateTo", null);
}
if (obj.getPlanStartDateFrom() != null) {
			st.setObject("plan_start_dateFrom", obj.getPlanStartDateFrom());
		} else {
			st.setObject("plan_start_dateFrom", null);
		}
		if (obj.getPlanStartDateTo() != null) {
			st.setObject("plan_start_dateTo", obj.getPlanStartDateTo());
		} else {
            st.setObject("plan_start_dateTo", null);
}
if (obj.getPlanEndDateFrom() != null) {
			st.setObject("plan_end_dateFrom", obj.getPlanEndDateFrom());
		} else {
			st.setObject("plan_end_dateFrom", null);
		}
		if (obj.getPlanEndDateTo() != null) {
			st.setObject("plan_end_dateTo", obj.getPlanEndDateTo());
		} else {
            st.setObject("plan_end_dateTo", null);
}
if (obj.getRealStartDateFrom() != null) {
			st.setObject("real_start_dateFrom", obj.getRealStartDateFrom());
		} else {
			st.setObject("real_start_dateFrom", null);
		}
		if (obj.getRealStartDateTo() != null) {
			st.setObject("real_start_dateTo", obj.getRealStartDateTo());
		} else {
            st.setObject("real_start_dateTo", null);
}
if (obj.getRealEndDateFrom() != null) {
			st.setObject("real_end_dateFrom", obj.getRealEndDateFrom());
		} else {
			st.setObject("real_end_dateFrom", null);
		}
		if (obj.getRealEndDateTo() != null) {
			st.setObject("real_end_dateTo", obj.getRealEndDateTo());
		} else {
            st.setObject("real_end_dateTo", null);
}
if (obj.getAttendees() != Integer.MIN_VALUE) {
			st.setObject("attendees", obj.getAttendees());
		} else {
            st.setObject("attendees", null);
}
if (obj.getIdVenue() != Integer.MIN_VALUE) {
			st.setObject("id_venue", obj.getIdVenue());
		} else {
            st.setObject("id_venue", null);
}
if (obj.getCreatedFrom() != null) {
			st.setObject("createdFrom", obj.getCreatedFrom());
		} else {
			st.setObject("createdFrom", null);
		}
		if (obj.getCreatedTo() != null) {
			st.setObject("createdTo", obj.getCreatedTo());
		} else {
            st.setObject("createdTo", null);
}
if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
            st.setObject("creator", null);
}
if (obj.getUpdatedFrom() != null) {
			st.setObject("updatedFrom", obj.getUpdatedFrom());
		} else {
			st.setObject("updatedFrom", null);
		}
		if (obj.getUpdatedTo() != null) {
			st.setObject("updatedTo", obj.getUpdatedTo());
		} else {
            st.setObject("updatedTo", null);
}
if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
            st.setObject("updator", null);
}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
            st.setObject("deleted", null);
}
if (obj.getDeletionTimeFrom() != null) {
			st.setObject("deletion_timeFrom", obj.getDeletionTimeFrom());
		} else {
			st.setObject("deletion_timeFrom", null);
		}
		if (obj.getDeletionTimeTo() != null) {
			st.setObject("deletion_timeTo", obj.getDeletionTimeTo());
		} else {
            st.setObject("deletion_timeTo", null);
}
if (obj.getAvatar() != null) {
			st.setObject("avatar", obj.getAvatar());
		} else {
            st.setObject("avatar", null);
}
if (obj.getBudget() != Double.MAX_VALUE) {
			st.setObject("budget", obj.getBudget());
		} else {
            st.setObject("budget", null);
}
	

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genInsertStatement(Connection dbConn, IModel model)
			throws SQLException {
		String sql = "SELECT sp_project_insert(:name,:code,:description,:id_type,:pm,:id_company,:is_template,:status,:event_date,:plan_start_date,:plan_end_date,:real_start_date,:real_end_date,:attendees,:id_venue,:creator,:avatar,:budget)";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		ProjectModel obj = (ProjectModel) model;

		// set parameters here
if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
			st.setObject("name", null);
}
if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
			st.setObject("code", null);
}
if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
			st.setObject("description", null);
}
if (obj.getIdType() != Integer.MIN_VALUE) {
			st.setObject("id_type", obj.getIdType());
		} else {
			st.setObject("id_type", null);
}
if (obj.getPm() != Integer.MIN_VALUE) {
			st.setObject("pm", obj.getPm());
		} else {
			st.setObject("pm", null);
}
if (obj.getIdCompany() != Integer.MIN_VALUE) {
			st.setObject("id_company", obj.getIdCompany());
		} else {
			st.setObject("id_company", null);
}
		if (obj.getIsTemplateSet()) {
			st.setObject("is_template", obj.getIsTemplate());
		} else {
			st.setObject("is_template", null);
}
if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
			st.setObject("status", null);
}
if (obj.getEventDate() != null) {
			st.setObject("event_date", obj.getEventDate());
		} else {
			st.setObject("event_date", null);
}
if (obj.getPlanStartDate() != null) {
			st.setObject("plan_start_date", obj.getPlanStartDate());
		} else {
			st.setObject("plan_start_date", null);
}
if (obj.getPlanEndDate() != null) {
			st.setObject("plan_end_date", obj.getPlanEndDate());
		} else {
			st.setObject("plan_end_date", null);
}
if (obj.getRealStartDate() != null) {
			st.setObject("real_start_date", obj.getRealStartDate());
		} else {
			st.setObject("real_start_date", null);
}
if (obj.getRealEndDate() != null) {
			st.setObject("real_end_date", obj.getRealEndDate());
		} else {
			st.setObject("real_end_date", null);
}
if (obj.getAttendees() != Integer.MIN_VALUE) {
			st.setObject("attendees", obj.getAttendees());
		} else {
			st.setObject("attendees", null);
}
if (obj.getIdVenue() != Integer.MIN_VALUE) {
			st.setObject("id_venue", obj.getIdVenue());
		} else {
			st.setObject("id_venue", null);
}
if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
			st.setObject("creator", null);
}
if (obj.getAvatar() != null) {
			st.setObject("avatar", obj.getAvatar());
		} else {
			st.setObject("avatar", null);
}
if (obj.getBudget() != Double.MAX_VALUE) {
			st.setObject("budget", obj.getBudget());
		} else {
			st.setObject("budget", null);
}
	

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genUpdateStatement(Connection dbConn, IModel model)
			throws SQLException {
		String sql = "SELECT sp_project_update(:id,:name,:code,:description,:id_type,:pm,:id_company,:is_template,:status,:event_date,:plan_start_date,:plan_end_date,:real_start_date,:real_end_date,:attendees,:id_venue,:updator,:deleted,:deletion_time,:avatar,:budget)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		ProjectModel obj = (ProjectModel) model;

		// set parameters here
if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
			st.setObject("id", null);
}
if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
			st.setObject("name", null);
}
if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
			st.setObject("code", null);
}
if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
			st.setObject("description", null);
}
if (obj.getIdType() != Integer.MIN_VALUE) {
			st.setObject("id_type", obj.getIdType());
		} else {
			st.setObject("id_type", null);
}
if (obj.getPm() != Integer.MIN_VALUE) {
			st.setObject("pm", obj.getPm());
		} else {
			st.setObject("pm", null);
}
if (obj.getIdCompany() != Integer.MIN_VALUE) {
			st.setObject("id_company", obj.getIdCompany());
		} else {
			st.setObject("id_company", null);
}
		if (obj.getIsTemplateSet()) {
			st.setObject("is_template", obj.getIsTemplate());
		} else {
			st.setObject("is_template", null);
}
if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
			st.setObject("status", null);
}
if (obj.getEventDate() != null) {
			st.setObject("event_date", obj.getEventDate());
		} else {
			st.setObject("event_date", null);
}
if (obj.getPlanStartDate() != null) {
			st.setObject("plan_start_date", obj.getPlanStartDate());
		} else {
			st.setObject("plan_start_date", null);
}
if (obj.getPlanEndDate() != null) {
			st.setObject("plan_end_date", obj.getPlanEndDate());
		} else {
			st.setObject("plan_end_date", null);
}
if (obj.getRealStartDate() != null) {
			st.setObject("real_start_date", obj.getRealStartDate());
		} else {
			st.setObject("real_start_date", null);
}
if (obj.getRealEndDate() != null) {
			st.setObject("real_end_date", obj.getRealEndDate());
		} else {
			st.setObject("real_end_date", null);
}
if (obj.getAttendees() != Integer.MIN_VALUE) {
			st.setObject("attendees", obj.getAttendees());
		} else {
			st.setObject("attendees", null);
}
if (obj.getIdVenue() != Integer.MIN_VALUE) {
			st.setObject("id_venue", obj.getIdVenue());
		} else {
			st.setObject("id_venue", null);
}
if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
			st.setObject("updator", null);
}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
			st.setObject("deleted", null);
}
if (obj.getDeletionTime() != null) {
			st.setObject("deletion_time", obj.getDeletionTime());
		} else {
			st.setObject("deletion_time", null);
}
if (obj.getAvatar() != null) {
			st.setObject("avatar", obj.getAvatar());
		} else {
			st.setObject("avatar", null);
}
if (obj.getBudget() != Double.MAX_VALUE) {
			st.setObject("budget", obj.getBudget());
		} else {
			st.setObject("budget", null);
}

	
		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genDeleteStatement(Connection dbConn, IModel query)
			throws SQLException {
		String sql = "select sp_project_delete(:id);";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

        ProjectModel obj = (ProjectModel) query;

		// set primary keys
st.setObject("id", obj.getId());


		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genCountStatement(Connection dbConn,
			IModelExt input) throws SQLException {
		String sql = "SELECT sp_project_count(:id,:name,:code,:description,:id_type,:pm,:id_company,:is_template,:status,:event_dateFrom,:event_dateTo,:plan_start_dateFrom,:plan_start_dateTo,:plan_end_dateFrom,:plan_end_dateTo,:real_start_dateFrom,:real_start_dateTo,:real_end_dateFrom,:real_end_dateTo,:attendees,:id_venue,:createdFrom,:createdTo,:creator,:updatedFrom,:updatedTo,:updator,:deleted,:deletion_timeFrom,:deletion_timeTo,:avatar,:budget)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		ProjectModelExt obj = (ProjectModelExt) input;

		// set parameters here
if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
            st.setObject("id", null);
}
if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
            st.setObject("name", null);
}
if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
            st.setObject("code", null);
}
if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
            st.setObject("description", null);
}
if (obj.getIdType() != Integer.MIN_VALUE) {
			st.setObject("id_type", obj.getIdType());
		} else {
            st.setObject("id_type", null);
}
if (obj.getPm() != Integer.MIN_VALUE) {
			st.setObject("pm", obj.getPm());
		} else {
            st.setObject("pm", null);
}
if (obj.getIdCompany() != Integer.MIN_VALUE) {
			st.setObject("id_company", obj.getIdCompany());
		} else {
            st.setObject("id_company", null);
}
		if (obj.getIsTemplateSet()) {
			st.setObject("is_template", obj.getIsTemplate());
		} else {
            st.setObject("is_template", null);
}
if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
            st.setObject("status", null);
}
if (obj.getEventDateFrom() != null) {
			st.setObject("event_dateFrom", obj.getEventDateFrom());
		} else {
			st.setObject("event_dateFrom", null);
		}
		if (obj.getEventDateTo() != null) {
			st.setObject("event_dateTo", obj.getEventDateTo());
		} else {
            st.setObject("event_dateTo", null);
}
if (obj.getPlanStartDateFrom() != null) {
			st.setObject("plan_start_dateFrom", obj.getPlanStartDateFrom());
		} else {
			st.setObject("plan_start_dateFrom", null);
		}
		if (obj.getPlanStartDateTo() != null) {
			st.setObject("plan_start_dateTo", obj.getPlanStartDateTo());
		} else {
            st.setObject("plan_start_dateTo", null);
}
if (obj.getPlanEndDateFrom() != null) {
			st.setObject("plan_end_dateFrom", obj.getPlanEndDateFrom());
		} else {
			st.setObject("plan_end_dateFrom", null);
		}
		if (obj.getPlanEndDateTo() != null) {
			st.setObject("plan_end_dateTo", obj.getPlanEndDateTo());
		} else {
            st.setObject("plan_end_dateTo", null);
}
if (obj.getRealStartDateFrom() != null) {
			st.setObject("real_start_dateFrom", obj.getRealStartDateFrom());
		} else {
			st.setObject("real_start_dateFrom", null);
		}
		if (obj.getRealStartDateTo() != null) {
			st.setObject("real_start_dateTo", obj.getRealStartDateTo());
		} else {
            st.setObject("real_start_dateTo", null);
}
if (obj.getRealEndDateFrom() != null) {
			st.setObject("real_end_dateFrom", obj.getRealEndDateFrom());
		} else {
			st.setObject("real_end_dateFrom", null);
		}
		if (obj.getRealEndDateTo() != null) {
			st.setObject("real_end_dateTo", obj.getRealEndDateTo());
		} else {
            st.setObject("real_end_dateTo", null);
}
if (obj.getAttendees() != Integer.MIN_VALUE) {
			st.setObject("attendees", obj.getAttendees());
		} else {
            st.setObject("attendees", null);
}
if (obj.getIdVenue() != Integer.MIN_VALUE) {
			st.setObject("id_venue", obj.getIdVenue());
		} else {
            st.setObject("id_venue", null);
}
if (obj.getCreatedFrom() != null) {
			st.setObject("createdFrom", obj.getCreatedFrom());
		} else {
			st.setObject("createdFrom", null);
		}
		if (obj.getCreatedTo() != null) {
			st.setObject("createdTo", obj.getCreatedTo());
		} else {
            st.setObject("createdTo", null);
}
if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
            st.setObject("creator", null);
}
if (obj.getUpdatedFrom() != null) {
			st.setObject("updatedFrom", obj.getUpdatedFrom());
		} else {
			st.setObject("updatedFrom", null);
		}
		if (obj.getUpdatedTo() != null) {
			st.setObject("updatedTo", obj.getUpdatedTo());
		} else {
            st.setObject("updatedTo", null);
}
if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
            st.setObject("updator", null);
}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
            st.setObject("deleted", null);
}
if (obj.getDeletionTimeFrom() != null) {
			st.setObject("deletion_timeFrom", obj.getDeletionTimeFrom());
		} else {
			st.setObject("deletion_timeFrom", null);
		}
		if (obj.getDeletionTimeTo() != null) {
			st.setObject("deletion_timeTo", obj.getDeletionTimeTo());
		} else {
            st.setObject("deletion_timeTo", null);
}
if (obj.getAvatar() != null) {
			st.setObject("avatar", obj.getAvatar());
		} else {
            st.setObject("avatar", null);
}
if (obj.getBudget() != Double.MAX_VALUE) {
			st.setObject("budget", obj.getBudget());
		} else {
            st.setObject("budget", null);
}

	
		return st.getPreparedStatement();
	}

/*
	private String fillHtmlTemplate(String template) {
		String html = template
				.replace(":id", Integer.toString(_id))
.replace(":name", HtmlUtil.genHtml(_name))
.replace(":code", HtmlUtil.genHtml(_code))
.replace(":description", HtmlUtil.genHtml(_description))
.replace(":id_type", Integer.toString(_id_type))
.replace(":pm", Integer.toString(_pm))
.replace(":id_company", Integer.toString(_id_company))
.replace(":is_template", HtmlUtil.genHtml(_isis_templateSet, _is_template))
.replace(":status", Integer.toString(_status))
.replace(":event_date", StringUtil.toDateTimeString(_event_date))
.replace(":plan_start_date", StringUtil.toDateTimeString(_plan_start_date))
.replace(":plan_end_date", StringUtil.toDateTimeString(_plan_end_date))
.replace(":real_start_date", StringUtil.toDateTimeString(_real_start_date))
.replace(":real_end_date", StringUtil.toDateTimeString(_real_end_date))
.replace(":attendees", Integer.toString(_attendees))
.replace(":id_venue", Integer.toString(_id_venue))
.replace(":created", StringUtil.toDateTimeString(_created))
.replace(":creator", Integer.toString(_creator))
.replace(":updated", StringUtil.toDateTimeString(_updated))
.replace(":updator", Integer.toString(_updator))
.replace(":deleted", HtmlUtil.genHtml(_isdeletedSet, _deleted))
.replace(":deletion_time", StringUtil.toDateTimeString(_deletion_time))
.replace(":avatar", HtmlUtil.genHtml(_avatar))
.replace(":budget", StringUtil.toString(_budget))

				;
		return html;
	}
*/

/*
	private String fillHtmlTemplate(String template) {
		String html = template
				.replace(":Id", Integer.toString(_Id))
.replace(":Name", HtmlUtil.genHtml(_Name))
.replace(":Code", HtmlUtil.genHtml(_Code))
.replace(":Description", HtmlUtil.genHtml(_Description))
.replace(":IdType", Integer.toString(_IdType))
.replace(":Pm", Integer.toString(_Pm))
.replace(":IdCompany", Integer.toString(_IdCompany))
.replace(":IsTemplate", HtmlUtil.genHtml(_isIsTemplateSet, _IsTemplate))
.replace(":Status", Integer.toString(_Status))
.replace(":EventDate", StringUtil.toDateTimeString(_EventDate))
.replace(":PlanStartDate", StringUtil.toDateTimeString(_PlanStartDate))
.replace(":PlanEndDate", StringUtil.toDateTimeString(_PlanEndDate))
.replace(":RealStartDate", StringUtil.toDateTimeString(_RealStartDate))
.replace(":RealEndDate", StringUtil.toDateTimeString(_RealEndDate))
.replace(":Attendees", Integer.toString(_Attendees))
.replace(":IdVenue", Integer.toString(_IdVenue))
.replace(":Created", StringUtil.toDateTimeString(_Created))
.replace(":Creator", Integer.toString(_Creator))
.replace(":Updated", StringUtil.toDateTimeString(_Updated))
.replace(":Updator", Integer.toString(_Updator))
.replace(":Deleted", HtmlUtil.genHtml(_isDeletedSet, _Deleted))
.replace(":DeletionTime", StringUtil.toDateTimeString(_DeletionTime))
.replace(":Avatar", HtmlUtil.genHtml(_Avatar))
.replace(":Budget", StringUtil.toString(_Budget))

				;
		return html;
	}
*/


	// ADDED CODE

	public int getAgendaCount() {
		return _agendaCount;
	}

	public void setAgendaCount(int agendaCount) {
		this._agendaCount = agendaCount;
	}

	public int getChecklistCount() {
		return _checklistCount;
	}

	public void setChecklistCount(int checklistCount) {
		this._checklistCount = checklistCount;
	}

	public int getQuotationCount() {
		return _quotationCount;
	}

	public void setQuotationCount(int quotationCount) {
		this._quotationCount = quotationCount;
	}

	public int getPhaseCount() {
		return _phaseCount;
	}

	public void setPhaseCount(int phaseCount) {
		this._phaseCount = phaseCount;
	}
	
	public int getEventCount() {
		return _eventCount;
	}

	public void setEventCount(int eventCount) {
		this._eventCount = eventCount;
	}
	
	public int getDocumentCount() {
		return _documentCount;
	}

	public void setDocumentCount(int documentCount) {
		this._documentCount = documentCount;
	}
	
	public int getReceivableCount() {
		return _receivableCount;
	}

	public void setReceivableCount(int receivableCount) {
		this._receivableCount = receivableCount;
	}

	public int getTeamAllocationCount() {
		return _allocationCount;
	}

	public void setTeamAllocationCount(int allocationCount) {
		this._allocationCount = allocationCount;
	}


	private int _agendaCount = 0;

	private int _checklistCount = 0;

	private int _quotationCount = 0;

	private int _phaseCount = 0;
	
	private int _eventCount = 0;
	
	private int _documentCount = 0;
	
	private int _receivableCount = 0;

	private int _allocationCount = 0;

	private List<PhaseModel> _phases;

	public List<PhaseModel> getPhases() {
		return _phases;
	}

	public void setPhases(List<PhaseModel> _phases) {
		this._phases = _phases;
	}
	
	private List<EventModel> _events;
	
	public List<EventModel> getEvents() {
		return _events;
	}

	public void setEvents(List<EventModel> _events) {
		this._events = _events;
	}
	
	private List<DocumentModel> _documents;
	
	public List<DocumentModel> getDocuments() {
		return _documents;
	}

	public void setDocuments(List<DocumentModel> _documents) {
		this._documents = _documents;
	}
	
	public Date getFirstDay() {
		if (_firstDay == null) {
			for (PhaseModel phase : _phases) {
				if (_firstDay == null) {
					_firstDay = phase.getFirstDay();
				} else {
					Date fistDay = phase.getFirstDay();
					if (fistDay != null && _firstDay.after(fistDay)) {
						_firstDay = fistDay;
					}
				}
			}
		}

		return _firstDay;
	}

	public Date getLastDay() {
		if (_lastDay == null) {
			for (PhaseModel phase : _phases) {
				if (_lastDay == null) {
					_lastDay = phase.getLastDay();
				} else {
					Date lastDay = phase.getLastDay();
					if (lastDay != null && _firstDay.before(lastDay)) {
						_lastDay = lastDay;
					}
				}
			}
		}

		return _lastDay;
	}

	public List<MonthInfo> getMonths() {
		return _months;
	}

	public void setMonths(List<MonthInfo> _months) {
		this._months = _months;
	}

	public StyleInfo getStyleInfo() {
		return _styleInfo;
	}

	public void setStyleInfo(StyleInfo _styleOption) {
		this._styleInfo = _styleOption;
	}

	private Date _firstDay = null;

	private Date _lastDay = null;

	private List<MonthInfo> _months;

	private StyleInfo _styleInfo;

}